;;;
;;; JaCoLiB
;;; Copyright (C) 2008 Alessandro Serra
;;; 
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;; 
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;; 
;;; You should have received a copy of the GNU General Public License
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
;;;

;;;; Created on 2008-07-25 21:15:39

(in-package :jacolib)

(defclass shell-channel (rpc-channel)
  ((name
    :TYPE string
    :READER shell-channel-name
    :INITARG :name)
   (shell
    :TYPE shell
    :READER shell-channel-shell
    :INITARG :shell))
  (:documentation "The jacolib system."))

; initialization

(defmethod initialize-instance :after ((channel shell-channel) &rest initargs)
  (declare (ignore initargs))
  (let* ((remote-shell (make-instance 'remote-shell 
                                      :rpc-client-stub (rpc-channel-client-stub channel) 
                                      :name (shell-channel-name channel)))
         (shell-server (make-instance 'shell-server 
                                      :shell (shell-channel-shell channel) 
                                      :callback-shell remote-shell)))
    (rpc-channel-set-server channel shell-server)
    (rpc-channel-set-client channel remote-shell)))

; quiting 

(defmethod rpc-channel-quit% ((channel shell-channel))
  (setf (slot-value channel 'shell) nil)
  (call-next-method))
